package cn.iocoder.yudao.module.system.service.ids;

import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;

import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginReqVO;
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthLoginRespVO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.auth.AdminAuthService;
import cn.iocoder.yudao.module.system.service.dept.DeptService;
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
import cn.iocoder.yudao.module.system.service.permission.RoleService;
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import cn.iocoder.yudao.module.system.util.IdsConfig;
import cn.iocoder.yudao.module.system.util.IdsUtils;
import com.alibaba.fastjson.JSONObject;
import com.xingyuv.captcha.util.StringUtils;
import org.apache.logging.log4j.util.Base64Util;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.nio.charset.StandardCharsets;
import java.util.*;

/**
 * @author lxj
 */
@Service
@Validated
public class IdsServiceImpl implements IdsService {


    @Resource
    private IdsConfig idsConfig;
    @Resource
    private AdminAuthService authService;
    @Resource
    private DeptService deptService;
    @Resource
    private AdminUserService userService;
    @Resource
    private TenantService tenantService;
    @Resource
    private PermissionService permissionService;
    @Resource
    private RoleService roleService;

    public static void main(String[] args) {
        String allGroupFullPaths = "EveryOne#根组织/10#融合出版系统/11#001/12#001$qewq";
        //groupFullPath -> EveryOne#根组织/10#融合出版系统/11#001/12#001$qewq
        System.out.println("ids新增用户参数allGroupFullPaths" + allGroupFullPaths);
        String[] split = allGroupFullPaths.split("/");
        if (split.length <= 2) {
            System.out.println("顶级部门");
        } else {
            System.out.println(split[split.length - 2]);
            String oneGroupFullPaths = split[split.length - 2];
            String[] split2 = oneGroupFullPaths.split("#");
            String idsGroupName = split2[1];
            System.out.println(idsGroupName);
        }
    }

    @Override
    public AuthLoginRespVO loginIDS(HttpServletRequest req, HttpServletResponse res, String trsidsssosessionid) {
        System.out.println("======================loginIDS======================");

        RestTemplate restTemplate = new RestTemplate();

        String idsloginurl = idsConfig.getIdsServiceUrl() + "/service?idsServiceType=httpssoservice&serviceName=findUserBySSOID";
        String coSessionId = req.getSession().getId();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        map.add("coAppName", idsConfig.getAppName());
        map.add("type", "json");
        map.add("coSessionId", coSessionId);
        map.add("ssoSessionId", trsidsssosessionid);
        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        ResponseEntity<String> response = restTemplate.postForEntity(idsloginurl, request, String.class);


        JSONObject result = JSONObject.parseObject(response.getBody());
        int code = result.getInteger("code");
        System.out.println(result);
        if (code == 200) {
            AuthLoginReqVO authLoginReqVO = new AuthLoginReqVO();
            authLoginReqVO.setPassword(result.getJSONObject("data").getJSONObject("user").getString("plainUserPwd"));
            authLoginReqVO.setUsername(IdsUtils.getUserNameFromIds(result));
            try {
                //登录生产系统
                return authService.login(authLoginReqVO);
            } catch (Exception e) {
                // 登录失败 返回跳转参数
                System.out.println(idsConfig.getServiceUrl() + "=========");
                String idsParameter = idsConfig.getIdsClientUrl() + "/globalLoginPage.jsp?coAppName="
                        + Base64Util.encode(idsConfig.getAppName()) + "&coSessionId=" + Base64Util.encode(coSessionId) + "&gSessionId="
                        + Base64Util.encode(req.getParameter("com.trs.idm.gSessionId")) + "&surl=" + Base64Util.encode(idsConfig.getServiceUrl());
                System.out.println(idsParameter + "=========");
            }
        } else {
            // 返回跳转参数
            System.out.println(idsConfig.getServiceUrl() + "=========");
            String idsParameter = idsConfig.getIdsClientUrl() + "/globalLoginPage.jsp?coAppName="
                    + Base64Util.encode(idsConfig.getAppName()) + "&coSessionId=" + Base64Util.encode(coSessionId) + "&gSessionId="
                    + Base64Util.encode(req.getParameter("com.trs.idm.gSessionId")) + "&surl=" + Base64Util.encode(idsConfig.getServiceUrl());
            System.out.println(idsParameter + "=========");

        }
        return null;
    }

    @Override
    public String loginRedirect(HttpServletRequest req) {
        System.out.println("======================loginRedirect======================");
        String coSessionId = req.getSession().getId();
        String redirectUrl = idsConfig.getIdsClientUrl() + "/LoginServlet?";
        redirectUrl = redirectUrl + "coAppName=" + Base64Util.encode(idsConfig.getAppName()) + "&coSessionId="
                + Base64Util.encode(coSessionId) + "&surl=" + Base64Util.encode(idsConfig.getServiceUrl());
        System.out.println("redirectUrl=========================================" + redirectUrl);

        return redirectUrl;
    }

    /*@Override
    public String checkIdsLoginRedirect(HttpServletRequest req) {
        String coSessionId = req.getSession().getId();
        System.out.println(coSessionId);
        String redirectUrl = idsConfig.getIdsClientUrl() + "/LoginServlet?";
        redirectUrl = redirectUrl + "coAppName=" + Base64Util.encode(idsConfig.getAppName()) + "&coSessionId="
                + Base64Util.encode(coSessionId) + "&surl=" + Base64Util.encode(idsConfig.getCheckIDSLoginUrl());
        return redirectUrl;
    }*/

    @Override
    public Boolean checkIDSLogin(HttpServletRequest req, String trsidsssosessionid) {
        String ssoSessionId = "";
        if (StringUtils.isNotEmpty(trsidsssosessionid)) {
            ssoSessionId = trsidsssosessionid;
        }
        RestTemplate restTemplate = new RestTemplate();

        String idsloginurl = idsConfig.getIdsServiceUrl() + "/service?idsServiceType=httpssoservice&serviceName=findUserBySSOID";
        String coSessionId = req.getSession().getId();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        map.add("coAppName", idsConfig.getAppName());
        map.add("type", "json");
        map.add("coSessionId", coSessionId);
        map.add("ssoSessionId", ssoSessionId);
        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        ResponseEntity<String> response = restTemplate.postForEntity(idsloginurl, request, String.class);

        JSONObject result = JSONObject.parseObject(response.getBody());
        int code = result.getInteger("code");
        return code == 200;
    }

    @Override
    public String getTenantName(HttpServletRequest req, String trsidsssosessionid) {
        String tenantName = "";
        RestTemplate restTemplate = new RestTemplate();

        String idsloginurl = idsConfig.getIdsServiceUrl() + "/service?idsServiceType=httpssoservice&serviceName=findUserBySSOID";
        String coSessionId = req.getSession().getId();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        map.add("coAppName", idsConfig.getAppName());
        map.add("type", "json");
        map.add("coSessionId", coSessionId);
        map.add("ssoSessionId", trsidsssosessionid);
        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        ResponseEntity<String> response = restTemplate.postForEntity(idsloginurl, request, String.class);

        JSONObject result = JSONObject.parseObject(response.getBody());
        int code = result.getInteger("code");
        if (code == 200) {
            tenantName = result.getJSONObject("data").getJSONObject("user").getString("loginAccountName");
            tenantName = StringUtils.substringBefore(tenantName, "@");
        }
        //return tenantName;
        return "系统管理";
    }

    /*ids退出接口*/
    @Override
    public Boolean idsLogout(String trsidsssosessionid) {
        RestTemplate restTemplate = new RestTemplate();
        String idsloginurl = idsConfig.getIdsServiceUrl() + "/service?idsServiceType=httpssoservice&serviceName=logout";
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        map.add("coAppName", idsConfig.getAppName());
        map.add("type", "json");
        map.add("ssoSessionId", trsidsssosessionid);
        HttpEntity<MultiValueMap<String, String>> req = new HttpEntity<>(map, headers);
        ResponseEntity<String> res = restTemplate.postForEntity(idsloginurl, req, String.class);
        JSONObject result = JSONObject.parseObject(res.getBody());
        int code = result.getInteger("code");
        return code == 200;
    }

    //用户登录名userName用户昵称nickName用户的姓firstName用户的名lastName用户实名全称trueNameEmailemail
    // 手机mobile电话tel密码原文plainUserPwd密码密文encryptedUserPwd身份证号creditID
    // 用户是否启用开通activedCA证书信息caStr职位jobPosition注册来源regFrom用户注册IP地址regIP用户注册时间createdDateAsLong
    // 机构主键groupId用户机构显示名称groupDisplayName机构全名称groupFullPath性别gender生日birthday国家nation省份province
    // 城市city教育程度education婚姻状况marriage激活状态activateStatus公司名称corpName传真fax用户编号userid
    @Override
    public String addUser(HttpServletRequest req, HttpServletResponse res) {
        System.out.println("执行新增用户操作");
        //处理ids带过来的数据
        Map<String, String> userMap = idsParameterHandling(req);
        System.out.println("ids新增用户参数" + userMap);
        //处理map
        UserCreateReqVO idsUser = idsUserFromat(userMap);
        Set<Long> postIds = new HashSet<>();
        idsUser.setPostIds(postIds);
        //租户信息
        //String tenantName = StringUtils.substringBefore(userMap.get("userName"), "@");
        //TenantDO tenantDO = tenantService.getTenantByName(tenantName);
        //if (tenantDO == null) {
        //    res.setHeader("ACTION_RESULT", "false");
        //} else {
        try {
            //Long id = userService.createUserByIds(idsUser, tenantDO.getId());
            Long id = userService.createUserByIds(idsUser, 1L);
            //赋予用户角色
            //RoleDO roleDO = roleService.selectByCodeAndTenantId(RoleCodeEnum.BASICS_ADMIN.getCode(), tenantDO.getId());
            //Set<Long> roleIds = new HashSet<>();
            //roleIds.add(roleDO.getId());
            //permissionService.assignUserRole(id, roleIds);


            if (id > 0) {
                res.setHeader("ACTION_RESULT", "true");
            } else {
                res.setHeader("ACTION_RESULT", "false");
            }
        } catch (Exception e) {
            res.setHeader("ACTION_RESULT", "false");
        }
        //}

        return "synchro";
    }


    //打开用户访问权限
    @Override
    public String openUser(HttpServletRequest req, HttpServletResponse res) {
        System.out.println("执行开启用户权限操作");
        Map<String, String> userMap = idsParameterHandling(req);
        UserCreateReqVO idsUser = idsUserFromat(userMap);
        AdminUserDO sysUser = userService.getUserByUsername(idsUser.getUsername());
        if (null == sysUser) {
            this.addUser(req, res);
        }
        try {
            userService.updateUserStatus(sysUser.getId(), 0);
            res.setHeader("ACTION_RESULT", "true");
        } catch (Exception e) {
            res.setHeader("ACTION_RESULT", "false");
        }
        return "synchro";
    }

    //关闭用户访问权限
    @Override
    public String closeUser(HttpServletRequest req, HttpServletResponse res) {
        System.out.println("执行开启用户权限操作");
        Map<String, String> userMap = idsParameterHandling(req);
        UserCreateReqVO idsUser = idsUserFromat(userMap);
        AdminUserDO sysUser = userService.getUserByUsername(idsUser.getUsername());
        if (null == sysUser) {
            this.addUser(req, res);
        }
        try {
            userService.updateUserStatus(sysUser.getId(), 1);
            res.setHeader("ACTION_RESULT", "true");
        } catch (Exception e) {
            res.setHeader("ACTION_RESULT", "false");
        }
        return "synchro";
    }

    //修改用户信息
    @Override
    public String updateUser(HttpServletRequest req, HttpServletResponse res) {
        System.out.println("执行更新用户操作");
        Map<String, String> userMap = idsParameterHandling(req);
        UserCreateReqVO idsUser = idsUserFromat(userMap);
        AdminUserDO sysUser = userService.getUserByUsername(idsUser.getUsername());
        if (null == sysUser) {
            return this.addUser(req, res);
        }
        if (!userService.isPasswordMatch(sysUser.getPassword(), idsUser.getPassword())) {
            userService.updateUserPassword(sysUser.getId(), idsUser.getPassword());
        }
        UserUpdateReqVO updateReqVO = new UserUpdateReqVO();
        updateReqVO.setId(sysUser.getId());
        updateReqVO.setPostIds(sysUser.getPostIds());
        updateReqVO.setUsername(idsUser.getUsername());
        updateReqVO.setEmail(idsUser.getEmail());
        updateReqVO.setMobile(idsUser.getMobile());
        updateReqVO.setDeptId(idsUser.getDeptId());
        updateReqVO.setNickname(idsUser.getNickname());
        try {
            userService.updateUser(updateReqVO);
            res.setHeader("ACTION_RESULT", "true");
        } catch (Exception e) {
            res.setHeader("ACTION_RESULT", "false");
        }
        return "synchro";
    }

    //删除用户信息
    @Override
    public String deleteUser(HttpServletRequest req, HttpServletResponse res) {
        System.out.println("执行ids删除用户操作");
        Map<String, String> userMap = idsParameterHandling(req);
        UserCreateReqVO idsUser = idsUserFromat(userMap);

        AdminUserDO sysUser = userService.getUserByUsername(idsUser.getUsername());
        if (null == sysUser) {
            this.addUser(req, res);
        }
        if (userService.isPasswordMatch(idsUser.getPassword(), sysUser.getPassword())) {
            //密码一样，同一用户
            userService.deleteUser(sysUser.getId());
            res.setHeader("ACTION_RESULT", "true");
        } else {
            System.out.println("当前用户ids密码和系统密码不同，不是同一用户！！！，如需继续操作请联系管理员。");
            res.setHeader("ACTION_RESULT", "false");
        }

        return "synchro";
    }

    //将用户分配到某部门
    @Override
    public String disOrgan(HttpServletRequest req, HttpServletResponse res) {
        System.out.println("执行分配机构操作");
        Map<String, String> userMap = idsParameterHandling(req);
        UserCreateReqVO idsUser = idsUserFromat(userMap);
        AdminUserDO sysUser = userService.getUserByUsername(idsUser.getUsername());
        if (null == sysUser) {
            this.addUser(req, res);
        }
        UserUpdateReqVO updateReqVO = new UserUpdateReqVO();
        updateReqVO.setId(sysUser.getId());
        updateReqVO.setDeptId(idsUser.getDeptId());
        try {
            userService.updateUser(updateReqVO);
            res.setHeader("ACTION_RESULT", "true");
        } catch (Exception e) {
            res.setHeader("ACTION_RESULT", "false");
        }
        return "synchro";
    }

    //将用户移除某部门
    @Override
    public String removeOrgan(HttpServletRequest req, HttpServletResponse res) {
        System.out.println("执行移除机构操作");
        Map<String, String> userMap = idsParameterHandling(req);
        UserCreateReqVO idsUser = idsUserFromat(userMap);
        AdminUserDO sysUser = userService.getUserByUsername(idsUser.getUsername());
        if (null == sysUser) {
            this.addUser(req, res);
        }
        UserUpdateReqVO updateReqVO = new UserUpdateReqVO();
        updateReqVO.setId(sysUser.getId());
        updateReqVO.setDeptId(null);
        try {
            userService.updateUser(updateReqVO);
            res.setHeader("ACTION_RESULT", "true");
        } catch (Exception e) {
            res.setHeader("ACTION_RESULT", "false");
        }
        return "synchro";
    }


    //新增部门
    @Override
    public String addOrgan(HttpServletRequest req, HttpServletResponse res) {
        System.out.println("执行新增机构操作");
        Map<String, String> userMap = idsParameterHandling(req);
        String parentName = getParentName(userMap.get("groupFullPath"));
        DeptDO parentDept = deptService.selectByUsername(parentName);
        if (parentDept == null) {
            res.setHeader("ACTION_RESULT", "false");
        } else {
            //String tenantName = StringUtils.substringBefore(userMap.get("groupDisplayName"), "@");
            //TenantDO tenantDO = tenantService.getTenantByName(tenantName);
            //if(tenantDO==null){
            //    res.setHeader("ACTION_RESULT", "false");
            //}else {
            DeptCreateReqVO createReqVO = new DeptCreateReqVO();
            createReqVO.setName(userMap.get("groupDisplayName"));
            createReqVO.setPhone(userMap.get("groupTel"));
            createReqVO.setEmail(userMap.get("groupMail"));
            createReqVO.setSort(Integer.valueOf(userMap.get("displayOrder")));
            if ("顶级部门".equals(parentName)) {
                createReqVO.setParentId(0L);
            } else {
                createReqVO.setParentId(parentDept.getId());
            }
            createReqVO.setStatus(0);
            try {
                //deptService.createDeptByIds(createReqVO, tenantDO.getId());
                deptService.createDeptByIds(createReqVO, 1L);
                res.setHeader("ACTION_RESULT", "true");
            } catch (Exception e) {
                res.setHeader("ACTION_RESULT", "false");
            }
            //}
        }
        return "synchro";
    }

    //修改部门信息
    @Override
    public String updateOrgan(HttpServletRequest req, HttpServletResponse res) {
        System.out.println("执行更新机构操作");
        Map<String, String> userMap = idsParameterHandling(req);
        DeptUpdateReqVO updateReqVO = new DeptUpdateReqVO();
        DeptDO dept = deptService.selectByUsername(userMap.get("groupDisplayName"));
        String parentName = getParentName(userMap.get("groupFullPath"));
        DeptDO parentDept = deptService.selectByUsername(parentName);
        if (null != dept) {
            updateReqVO.setId(dept.getId());
            updateReqVO.setName(userMap.get("groupDisplayName"));
            updateReqVO.setPhone(userMap.get("groupTel"));
            updateReqVO.setEmail(userMap.get("groupMail"));
            updateReqVO.setSort(Integer.valueOf(userMap.get("displayOrder")));
            if ("顶级部门".equals(parentName)) {
                updateReqVO.setParentId(0L);
            } else {
                updateReqVO.setParentId(parentDept.getId());
            }
            try {
                deptService.updateDept(updateReqVO);
                res.setHeader("ACTION_RESULT", "true");
            } catch (Exception e) {
                res.setHeader("ACTION_RESULT", "false");
            }
        } else {
            res.setHeader("ACTION_RESULT", "false");
        }
        return "synchro";
    }

    //删除部门
    @Override
    public String deleteOrgan(HttpServletRequest req, HttpServletResponse res) {
        Map<String, String> userMap = idsParameterHandling(req);
        int n = 0;
        DeptDO sysDept = deptService.selectByUsername(userMap.get("groupDisplayName"));
        if (null != sysDept) {
            try {
                deptService.deleteDept(sysDept.getId());
                res.setHeader("ACTION_RESULT", "true");
            } catch (Exception e) {
                res.setHeader("ACTION_RESULT", "false");
            }
        } else {
            res.setHeader("ACTION_RESULT", "false");
        }
        return "synchro";
    }


    /**
     * ids参数处理
     *
     * @param req HttpServletRequest
     * @return userMap
     */
    public Map<String, String> idsParameterHandling(HttpServletRequest req) {
        Map<String, String> userMap = new HashMap<>();
        Enumeration em = req.getParameterNames();
        while (em.hasMoreElements()) {
            String name = (String) em.nextElement();
            String value = "";
            if (!StringUtils.isEmpty(req.getParameter(name))) {
                value = req.getParameter(name);
            } else {
                value = "";
            }
            userMap.put(name, value);
        }
        return userMap;
    }

    /**
     * 根据ids参数中组织全路径获取属于本业务系统的groupName
     *
     * @param allGroupFullPaths "EveryOne#根组织/1254#职业教育/1257#出版社;EveryOne#根组织/1730#课程实施监测/1758#语文;EveryOne#根组织/1730#课程实施监测/1759#数学;"
     * @return
     */
    public Long getDeptIdFromAllGroupFullPaths(String allGroupFullPaths) {
        System.out.println("ids新增用户参数allGroupFullPaths" + allGroupFullPaths);
        String[] split = allGroupFullPaths.split("/");
        String oneGroupFullPaths = split[split.length - 1];
        String[] split2 = oneGroupFullPaths.split("#");
        String idsGroupName = split2[1];
        System.out.println("idsGroupName===========================" + idsGroupName);
        idsGroupName = idsGroupName.replace(";", "");
        DeptListReqVO reqVO = new DeptListReqVO();
        reqVO.setName(idsGroupName);
        reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());

        List<DeptDO> sysDeptDOS = deptService.getDeptList(reqVO);
        return sysDeptDOS.get(0).getId();
    }

    /**
     * 根据ids参数中组织全路径获取属于本业务系统的groupName
     *
     * @param allGroupFullPaths "EveryOne#根组织/1254#职业教育/1257#出版社;EveryOne#根组织/1730#课程实施监测/1758#语文;EveryOne#根组织/1730#课程实施监测/1759#数学;"
     * @return
     */
    public String getParentName(String allGroupFullPaths) {

        String[] split = allGroupFullPaths.split("/");
        if (split.length <= 2) {
            return "顶级部门";
        } else {
            System.out.println(split[split.length - 2]);
            String oneGroupFullPaths = split[split.length - 2];
            String[] split2 = oneGroupFullPaths.split("#");
            String idsGroupName = split2[1];
            return idsGroupName;
        }
    }

    /**
     * 处理ids传递的参数map
     *
     * @return
     */
    public UserCreateReqVO idsUserFromat(Map<String, String> userMap) {
        UserCreateReqVO user = new UserCreateReqVO();
        String userName = userMap.get("userName");
        user.setUsername(userName);
        user.setPassword(userMap.get("plainUserPwd"));
        user.setEmail(userMap.get("email"));
        user.setMobile(userMap.get("mobile"));
        if (StringUtils.isEmpty(userMap.get("nickName"))) {
            user.setNickname(userName);
        } else {
            user.setNickname(userMap.get("nickName"));
        }

        Long deptId = getDeptIdFromAllGroupFullPaths(userMap.get("allGroupFullPaths"));
        user.setDeptId(deptId);
        System.out.println("ids新增用户参数deptId" + deptId);
        return user;
    }

}
